<?php

/**
 * Created by PhpStorm.
 * User: user
 * Date: 2017/3/9
 * Time: 14:59
 */
class AhpPgModRelation extends Eloquent
{
    protected $table = 'ahp_pg_mod_relation';

    public static function getPgModEleDetails($page_id){
        /* $mod_id = AhpPgModEleRelation::where('pg_id',$page_id)->orderBy('id','asc')->groupBy('mod_id')->select('mod_id')->get()->toArray();
         $data = AhpBasePage::where('id',$page_id)->first();
         $mod = array();
         foreach($mod_id as $v){
             $module_base = AhpModuleBase::where('id',$v)->first();
             if(!empty($module_base)){
                 $ele_id = AhpPgModEleRelation::where('pg_id',$page_id)->where('mod_id',$v)->orderBy('id','asc')->select('ele_id')->get()->toArray();
                 $module_base->ele = AhpElementBase::whereIn('id',$ele_id)->get();
                 $mod[] = $module_base;
             }
         }
         $data->mod = $mod;
         return $data;*/
        $data = AhpBasePage::where('id',$page_id)->first();
        $pg_mod = AhpPgModRelation::where('pg_id',$page_id)->orderBy('id','asc')->get();
        $mod = array();
        foreach ($pg_mod as $item) {
            $module_base = AhpModuleBase::where('id',$item->mod_id)->first();
            if(!empty($module_base)){
                $ele = array();
                $ele_id = AhpRModEleRelation::where('r_id',$item->id)->orderBy('id','asc')->select('ele_id')->get()->toArray();
                foreach($ele_id as $v){
                    $ele[] = AhpElementBase::whereIn('id',$v)->first();
                }
                $module_base->ele = $ele;
                $mod[] = $module_base;
            }
        }
        $data->mod = $mod;
        return $data;
    }
}